#include<stdio.h>

int main()
{
	int arr[32];int i = 0;
	int n;
	arr[0] = 0;
	arr[1] = 1;
	for ( i = 2; i < 32; i++){
		arr[i] = arr[i - 1] + arr[i - 2];
	}
	i = 0;
	scanf("%d", &n);
	int flag = 1;
	while (flag)
	{
		if (n>arr[i] && n<arr[i + 1])
			flag = 0;
		if (n = arr[i])
		    flag = 0;
		i++;
	}
	i = i - 1;
	int count = 0;
	if (n = arr[i])
		count = 0;
	else{
		flag = (n - arr[i])<(arr[i + 1] - n) ? i : (i + 1);
		if (flag = (i + 1))
			count = arr[flag] - n;
		if (flag=i)
			count = n - arr[flag];
	}
	printf("%d", count);
	return 0;
}